<?php
/**
 * Created by Zhy
 * User: Zhy
 * Date: 2024/1/24
 * Time: 15:09
 */

namespace app\admin\controller;

use think\Db;
use think\Request;

class Projectconfig extends Base
{
    /**
     * 数据保护政策
     * @return mixed|\think\response\Json
     * @throws \think\Exception
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\ModelNotFoundException
     * @throws \think\exception\DbException
     * @throws \think\exception\PDOException
     */
    public function privateAgreement(){
        if(Request::instance()->isPost()){
            $content_en = input('content_en');
            $content_es = input('content_es');
            $content_tp = input('content_tp');
            $res = Db::table('up_project_config')
                ->where('id', 1)
                ->update([
                    'content_en' => $content_en,
                    'content_es' => $content_es,
                    'content_tp' => $content_tp,
                    'time'       => initTime()
                ]);
            if($res){
                return json(['code' => 200, 'msg' => '保存成功']);
            }else{
                return json(['code' => 100, 'msg' => '保存失败']);
            }
        }
        $data = Db::table('up_project_config')
            ->where('id', 1)
            ->field('content_en, content_es, content_tp')
            ->find();
        $this->assign('data', $data);
        return $this->fetch();
    }

    /**
     * 隐私政策
     * @return mixed|\think\response\Json
     * @throws \think\Exception
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\ModelNotFoundException
     * @throws \think\exception\DbException
     * @throws \think\exception\PDOException
     */
    public function ysAgreement(){
        if(Request::instance()->isPost()){
            $content_en = input('content_en');
            $content_es = input('content_es');
            $content_tp = input('content_tp');
            $res = Db::table('up_project_config')
                ->where('id', 2)
                ->update([
                    'content_en' => $content_en,
                    'content_es' => $content_es,
                    'content_tp' => $content_tp,
                    'time'       => initTime()
                ]);
            if($res){
                return json(['code' => 200, 'msg' => '保存成功']);
            }else{
                return json(['code' => 100, 'msg' => '保存失败']);
            }
        }
        $data = Db::table('up_project_config')
            ->where('id', 2)
            ->field('content_en, content_es, content_tp')
            ->find();
        $this->assign('data', $data);
        return $this->fetch();
    }

    /**
     * 公司介绍
     * @return mixed|\think\response\Json
     * @throws \think\Exception
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\ModelNotFoundException
     * @throws \think\exception\DbException
     * @throws \think\exception\PDOException
     */
    public function companyIntro(){
        if(Request::instance()->isPost()){
            $content_en = input('content_en');
            $content_es = input('content_es');
            $content_tp = input('content_tp');
            $res = Db::table('up_project_config')
                ->where('id', 3)
                ->update([
                    'content_en' => $content_en,
                    'content_es' => $content_es,
                    'content_tp' => $content_tp,
                    'time'       => initTime()
                ]);
            if($res){
                return json(['code' => 200, 'msg' => '保存成功']);
            }else{
                return json(['code' => 100, 'msg' => '保存失败']);
            }
        }
        $data = Db::table('up_project_config')
            ->where('id', 3)
            ->field('content_en, content_es, content_tp')
            ->find();
        $this->assign('data', $data);
        return $this->fetch();
    }

    /**
     * 联系我们
     * @return mixed|\think\response\Json
     * @throws \think\Exception
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\ModelNotFoundException
     * @throws \think\exception\DbException
     * @throws \think\exception\PDOException
     */
    public function contactUs(){
        if(Request::instance()->isPost()){
            $content_en = input('content_en');
            $content_es = input('content_es');
            $content_tp = input('content_tp');
            $res = Db::table('up_project_config')
                ->where('id', 4)
                ->update([
                    'content_en' => $content_en,
                    'content_es' => $content_es,
                    'content_tp' => $content_tp,
                    'time'       => initTime()
                ]);
            if($res){
                return json(['code' => 200, 'msg' => '保存成功']);
            }else{
                return json(['code' => 100, 'msg' => '保存失败']);
            }
        }
        $data = Db::table('up_project_config')
            ->where('id', 4)
            ->field('content_en, content_es, content_tp')
            ->find();
        $this->assign('data', $data);
        return $this->fetch();
    }

    /**
     * 总部国家
     * @return mixed|\think\response\Json
     * @throws \think\Exception
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\ModelNotFoundException
     * @throws \think\exception\DbException
     * @throws \think\exception\PDOException
     */
    public function companyCountry(){
        if(Request::instance()->isPost()){
            $content_en = input('content_en');
            $content_es = input('content_es');
            $content_tp = input('content_tp');
            $res = Db::table('up_project_config')
                ->where('id', 5)
                ->update([
                    'content_en' => $content_en,
                    'content_es' => $content_es,
                    'content_tp' => $content_tp,
                    'time'       => initTime()
                ]);
            if($res){
                return json(['code' => 200, 'msg' => '保存成功']);
            }else{
                return json(['code' => 100, 'msg' => '保存失败']);
            }
        }
        $data = Db::table('up_project_config')
            ->where('id', 5)
            ->field('content_en, content_es, content_tp')
            ->find();
        $this->assign('data', $data);
        return $this->fetch();
    }

    /**
     * 公司具体地址
     * @return mixed|\think\response\Json
     * @throws \think\Exception
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\ModelNotFoundException
     * @throws \think\exception\DbException
     * @throws \think\exception\PDOException
     */
    public function companyAddress(){
        if(Request::instance()->isPost()){
            $content_en = input('content_en');
            $content_es = input('content_es');
            $content_tp = input('content_tp');
            $res = Db::table('up_project_config')
                ->where('id', 6)
                ->update([
                    'content_en' => $content_en,
                    'content_es' => $content_es,
                    'content_tp' => $content_tp,
                    'time'       => initTime()
                ]);
            if($res){
                return json(['code' => 200, 'msg' => '保存成功']);
            }else{
                return json(['code' => 100, 'msg' => '保存失败']);
            }
        }
        $data = Db::table('up_project_config')
            ->where('id', 6)
            ->field('content_en, content_es, content_tp')
            ->find();
        $this->assign('data', $data);
        return $this->fetch();
    }

    /**
     * 关于我们
     * @return mixed|\think\response\Json
     * @throws \think\Exception
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\ModelNotFoundException
     * @throws \think\exception\DbException
     * @throws \think\exception\PDOException
     */
    public function aboutUs(){
        if(Request::instance()->isPost()){
            $content_en = input('content_en');
            $content_es = input('content_es');
            $content_tp = input('content_tp');
            $res = Db::table('up_project_config')
                ->where('id', 7)
                ->update([
                    'content_en' => $content_en,
                    'content_es' => $content_es,
                    'content_tp' => $content_tp,
                    'time'       => initTime()
                ]);
            if($res){
                return json(['code' => 200, 'msg' => '保存成功']);
            }else{
                return json(['code' => 100, 'msg' => '保存失败']);
            }
        }
        $data = Db::table('up_project_config')
            ->where('id', 7)
            ->field('content_en, content_es, content_tp')
            ->find();
        $this->assign('data', $data);
        return $this->fetch();
    }

    /**
     * LOGO
     * @return mixed|\think\response\Json
     * @throws \think\Exception
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\ModelNotFoundException
     * @throws \think\exception\DbException
     * @throws \think\exception\PDOException
     */
    public function logo(){
        if(Request::instance()->isPost()){
            $content_en = input('content_en');
            $res = Db::table('up_project_config')
                ->where('id', 8)
                ->update([
                    'content_en' => $content_en,
                    'time'       => initTime()
                ]);
            if($res){
                return json(['code' => 200, 'msg' => '保存成功']);
            }else{
                return json(['code' => 100, 'msg' => '保存失败']);
            }
        }
        $data = Db::table('up_project_config')
            ->where('id', 8)
            ->field('content_en')
            ->find();
        $this->assign('data', $data);
        return $this->fetch();
    }
}